package com.jiuyun.Servlet;

import com.google.gson.Gson;
import com.jiuyun.vo.ChartData;
import com.jiuyun.vo.RaderChar;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/rader")
public class RaderServlet extends HttpServlet {

    Gson gson = new Gson();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //本应该来自 数据库
        String indicator[]={"name : 守约", "max: 6500","name: '人脉', max: 16000","name: '资产', max: 30000","name: '身份', max: 38000"};
        int data[]={4200, 3000, 20000, 35000, 50000, 18000};
        RaderChar cd = new RaderChar();
        String s = gson.toJson(cd);
        //如何让servlet返回json数据
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        //输出流
        PrintWriter out = response.getWriter();
        out.println(s);  //数据
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
